package com.kc.muzi102.midautumnandroid

import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.allen.library.interceptor.Transformer
import com.allen.library.interfaces.ILoadingView
import com.allen.library.observer.StringObserver
import com.kc.muzi102.midautumnandroid.api.ApiHelper
import com.kc.muzi102.midautumnandroid.widget.LoadingDialog

class MainActivity : AppCompatActivity() {
    private var loading_dialog: ILoadingView? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        loading_dialog = LoadingDialog(this)
    }

    fun onViewOnClick(view: View) {
        when (view.id) {
            R.id.tbn_test -> {
//                TestRequest()
            }
            R.id.tbn_one -> {
                showToast("点击了第二个案件")
            }
        }
    }

    fun showToast(content: String) {
        Toast.makeText(this, content, Toast.LENGTH_SHORT).show()
    }

    /**
     *
     */
    fun TestRequest() {
        ApiHelper
            .getMidAutumn()
            .getTest()
            .compose(Transformer.switchSchedulers(loading_dialog))
            .subscribe(object : StringObserver() {
                override fun onSuccess(data: String?) {
                    showToast(data.toString())
                }

                override fun onError(errorMsg: String?) {
                    showToast(errorMsg.toString())
                }
            })

//        ApiHelper
//            .getMidAutumn()
//            .getTest()
//            .compose(Transformer.switchSchedulers(loading_dialog))
//            .subscribe(object : DataObserver<TestControllerBean>() {
//                override fun onError(errorMsg: String?) {
//
//                }
//
//                override fun onSuccess(data: TestControllerBean?) {
//
//                }
//
//            })
    }
}
